package com.ruoyi.web.controller.zsix;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsix.domain.formComponents.FormDataValue;
import com.ruoyi.zsix.domain.model.QueryParamDto;
import com.ruoyi.zsix.service.IFormValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
//@Slf4j
@RequestMapping("/formData")
public class FormValueController extends BaseController {
    @Autowired
    private IFormValueService formValueService;

    /**
     * 查询表单数据集
     */
    @Log(title = "根据表单id获取数据列表" , businessType = BusinessType.EXPORT)
    @PostMapping({"/getDataById"})
    public TableDataInfo getFormData(@RequestBody QueryParamDto paramDto) {
        startPage();
        List<Map<String, Object>> list=formValueService.getFormData(paramDto);
        return getDataTable(list);
    }
    /**
     * 保存表单数据
     * @param formDataValue
     * @return
     */
    @Log(title = "保存表单数据" , businessType = BusinessType.EXPORT)
    @PostMapping("/saveFormDataValue")
    public AjaxResult saveFormDataValue(@RequestBody FormDataValue formDataValue) throws Exception {
        String msg=formValueService.saveFormValueByJson(formDataValue);
        if(!msg.equals("error"))
            return success(msg);
        else
            return error("数据写入失败");
    }
}
